package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * 公共的接口
 */
@RestController
@Slf4j
@Api(tags = "公共接口")
@RequestMapping("/admin/common")
public class CommonController {
@Autowired
    AliOssUtil aliOssUtil;
    /**
     * 上传图片
     */
    @PostMapping("/upload")
    @ApiOperation("上传图片")
    public Result upload(MultipartFile file)throws Exception {
        UUID uuid = UUID.randomUUID();
        // 调用阿里云oss的工具类
        String url = aliOssUtil.upload(file.getBytes(),uuid.toString());
        //调用方法 获取结果
        // 返回前端
        return Result.success(url);
    }

}
